
package ucm.module;

import air_cp5620.dao.DAO;
import javax.swing.JOptionPane;
import java.sql.*;


public class UC_ModUserM {

    private DAO dbCon = null;
    private String userid = null;
    private String password = null;

    public UC_ModUserM(String userid,String password) {
        this.userid = userid;
        this.password = password;
        dbCon = new DAO();
    }


    public boolean modify() {
        String sql = null;
        Connection con = dbCon.getConnection();
        if (con == null) {
            JOptionPane.showMessageDialog(null, "Don't get connection!");
            return false;
        }
        try {
            Statement stmt = con.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE);
            sql = "update tbl_user set password='" + password + "' where userid='" + userid + "'";
            stmt.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Modify password is successful!");
            return true;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Modify password error！");
            e.printStackTrace();
            return false;
        }
    }
}
